from pathlib import Path

from PIL import Image, ImageOps
from reportlab.graphics import renderPM


class ImageConversion:
    def __init__(self, filename: str = None, savefile: str = None):
        self.image = Image.open(filename)
        self.savefile = str(Path(savefile) / Path(filename).stem)
        print(self.savefile)

    def png(self):
        save = self.savefile + ".png"
        self.image.save(save, 'PNG')
        self.close()

    def jpg(self):
        save = self.savefile + ".jpg"
        image = self.image.convert('RGB')
        image.save(save, 'JPEG')
        self.close()

    def bmp(self):
        save = self.savefile + ".bmp"
        self.image.save(save, 'BMP')
        self.close()

    def ico(self, size=(256, 256)):
        save = self.savefile + ".ico"
        image = ImageOps.fit(self.image, size=[256, 256])
        image.save(save, 'ICO', sizes=[size])
        self.close()

    def webp(self):
        save = self.savefile + ".webp"
        self.image.save(save, 'WEBP')
        self.close()

    def close(self):
        self.image.close()


class SVGConversion:
    def __init__(self, filename):
        pass


if __name__ == '__main__':
    from svglib.svglib import svg2rlg

    svg = svg2rlg(r'F:\PythonObject\office-tools\resource\image\access.svg')
    renderPM.drawToFile(svg, "circos.webp", fmt="webp", bg=0xffffff)
